package com.mmy.controller.oa;


import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSONObject;
import com.mmy.controller.Common;
import com.mmy.domain.sys.TSysUser;
import com.mmy.service.oa.impl.CashierService;

@Controller
public class CashierController {
	
	@Autowired
	CashierService cashierService;
	@Autowired
	Common common;

	private static Logger logger = LoggerFactory.getLogger(CashierController.class);
	
	/**
	 * 函数功能说明：跳转--订单出纳审核页
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人  liys
	 * @date 创建日期 2021.04.06
	 */
	@RequestMapping("/cashier")
	public String toCashierPaidList(Model model,HttpServletRequest request) {
		
		String type = request.getParameter("type");
		model.addAttribute("type",type);
		String sort = request.getParameter("sort");
		String strState = request.getParameter("state");
		model.addAttribute("sort",sort);
		int iState = Integer.parseInt(strState);
		model.addAttribute("state",iState);
		if(iState == 4)return "OA/cashier/CashierOrderCancel";
		else return "OA/cashier/CashierOrderPaid";
	}
	
	/**
	 * 函数功能说明：异步--获取审核列表内容
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人  liys
	 * @date 创建日期 2021.04.06
	 */
	@RequestMapping("/cashierjson")
	@ResponseBody
	public String getCashierJson(HttpSession session,HttpServletRequest request,String sort,String state,String type,String cashierState) {
		
		int page = Integer.parseInt(request.getParameter("page"));
		int rows = Integer.parseInt(request.getParameter("rows"));
		int index = (page - 1) * rows;
		int count = rows;
		TSysUser tSysUser = (TSysUser) session.getAttribute("tSysUser");
		int iOrgID = tSysUser.getOrgID();
		String table = common.getViewName(sort);
		int iState = Integer.parseInt(state);
		List<Map<String,Object>> res = cashierService.findCashierList(iOrgID, table,iState,type,index,count,cashierState);
		return JSONObject.toJSONString(res);
	}
	
	/**
	 * 函数功能说明：通过审核
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 liys
	 * @date 创建日期 修改日期 2021.04.07
	 */
	@RequestMapping("/cashierpass")
	@ResponseBody
	public String cashierPass(HttpServletRequest request, HttpSession session, String checkList,String sort) {
		
		String table = common.getTableName(sort);
		TSysUser tSysUser = (TSysUser) session.getAttribute("tSysUser");
		int iOrgID = tSysUser.getUserID();
		String[] arrChecked = checkList.split(",");
		for (String str : arrChecked) {
			int iID = Integer.parseInt(str);
			cashierService.cashierPass(table, iID, iOrgID);
		}
		return null;
	}
	
	/**
	 * 函数功能说明：驳回审核
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @throws 异常处理说明
	 * @author 创建人 liys
	 * @date 创建日期 修改日期 2021.04.07
	 */
	@RequestMapping("/cashierfail")
	@ResponseBody
public String cashierFail(HttpServletRequest request, HttpSession session, String checkList,String sort) {
		
		String table = common.getTableName(sort);
		TSysUser tSysUser = (TSysUser) session.getAttribute("tSysUser");
		int iOrgID = tSysUser.getUserID();
		String[] arrChecked = checkList.split(",");
		for (String str : arrChecked) {
			int iID = Integer.parseInt(str);
			cashierService.cashierPass(table, iID, iOrgID);
		}
		return null;
	}
	

	
}
